home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / programs / internet / tcp / amitcp / amitcp-api-22.lha / AmiTCP-2.2 / netinclude / net / if.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-12  |  12.2 KB  |  343 lines

  1. #ifndef IF_H
  2. #define IF_H
  3. /* $Id: if.h,v 1.11 1993/08/04 22:15:13 ppessi Exp $
  4.  *
  5.  * Copyright (c) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>,
  6.  *                    Helsinki University of Technology, Finland.
  7.  *                    All rights reserved.
  8.  *
  9.  * if.h --- Network Interface 
  10.  *
  11.  * HISTORY
  12.  * $Log: if.h,v $
  13.  * Revision 1.11  1993/08/04  22:15:13  ppessi
  14.  * Removed sockaddr_sana2 from public interface.
  15.  *
  16.  * Revision 1.10  1993/08/01  19:30:23  ppessi
  17.  * Added sockaddr_sana2 structure definitions here.
  18.  *
  19.  * Revision 1.9  1993/06/04  11:16:15  jraja
  20.  * Fixes for first public release.
  21.  *
  22.  * Revision 1.8  1993/05/16  21:09:43  ppessi
  23.  * RCS version changed.
  24.  *
  25.  * Revision 1.7  1993/04/19  02:10:55  ppessi
  26.  * arp protos removed.
  27.  *
  28.  * Revision 1.6  93/04/13  22:20:01  22:20:01  jraja (Jarno Tapio Rajahalme)
  29.  * Fixed typo on comment.
  30.  * 
  31.  * Revision 1.5  93/04/11  22:21:14  22:21:14  jraja (Jarno Tapio Rajahalme)
  32.  * Removed unnecessary casts from function pointers, Changed ellipses to 
  33.  * prototypes.
  34.  * 
  35.  * Revision 1.4  93/03/10  21:30:34  21:30:34  ppessi (Pekka Pessi)
  36.  *     Added IF_H
  37.  * 
  38.  * Revision 1.3  93/03/05  03:12:09  03:12:09  ppessi (Pekka Pessi)
  39.  * Compiles with SASC. Initial test version
  40.  * 
  41.  * Revision 1.2  93/02/25  19:51:14  19:51:14  ppessi (Pekka Pessi)
  42.  * Added prototypes
  43.  * 
  44.  * Revision 1.1  92/11/20  14:58:42  14:58:42  jraja (Jarno Tapio Rajahalme)
  45.  * Initial revision
  46.  * 
  47.  *
  48.  */
  49.  
  50. /* 
  51.  * Mach Operating System
  52.  * Copyright (c) 1992 Carnegie Mellon University
  53.  * All Rights Reserved.
  54.  * 
  55.  * Permission to use, copy, modify and distribute this software and its
  56.  * documentation is hereby granted, provided that both the copyright
  57.  * notice and this permission notice appear in all copies of the
  58.  * software, derivative works or modified versions, and any portions
  59.  * thereof, and that both notices appear in supporting documentation.
  60.  * 
  61.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  62.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  63.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  64.  * 
  65.  * Carnegie Mellon requests users of this software to return to
  66.  * 
  67.  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  68.  *  School of Computer Science
  69.  *  Carnegie Mellon University
  70.  *  Pittsburgh PA 15213-3890
  71.  * 
  72.  * any improvements or extensions that they make and grant Carnegie Mellon 
  73.  * the rights to redistribute these changes.
  74.  */
  75. /*
  76.  * HISTORY
  77.  * Log:    if.h,v
  78.  * Revision 2.2  92/05/25  14:44:36  rwd
  79.  *     Fix includes.
  80.  *     [92/05/18            rwd]
  81.  * 
  82.  * Revision 2.1  92/04/21  17:13:59  rwd
  83.  * BSDSS
  84.  * 
  85.  *
  86.  */
  87.  
  88. /*
  89.  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
  90.  * All rights reserved.
  91.  *
  92.  * Redistribution and use in source and binary forms, with or without
  93.  * modification, are permitted provided that the following conditions
  94.  * are met:
  95.  * 1. Redistributions of source code must retain the above copyright
  96.  *    notice, this list of conditions and the following disclaimer.
  97.  * 2. Redistributions in binary form must reproduce the above copyright
  98.  *    notice, this list of conditions and the following disclaimer in the
  99.  *    documentation and/or other materials provided with the distribution.
  100.  * 3. All advertising materials mentioning features or use of this software
  101.  *    must display the following acknowledgement:
  102.  *    This product includes software developed by the University of
  103.  *    California, Berkeley and its contributors.
  104.  * 4. Neither the name of the University nor the names of its contributors
  105.  *    may be used to endorse or promote products derived from this software
  106.  *    without specific prior written permission.
  107.  *
  108.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  109.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  110.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  111.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  112.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  113.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  114.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  115.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  116.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  117.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  118.  * SUCH DAMAGE.
  119.  *
  120.  *    @(#)if.h    7.11 (Berkeley) 3/19/91
  121.  */
  122.  
  123. /*
  124.  * Structures defining a network interface, providing a packet
  125.  * transport mechanism (ala level 0 of the PUP protocols).
  126.  *
  127.  * Each interface accepts output datagrams of a specified maximum
  128.  * length, and provides higher level routines with input datagrams
  129.  * received from its medium.
  130.  *
  131.  * Output occurs when the routine if_output is called, with three parameters:
  132.  *    (*ifp->if_output)(ifp, m, dst)
  133.  * Here m is the mbuf chain to be sent and dst is the destination address.
  134.  * The output routine encapsulates the supplied datagram if necessary,
  135.  * and then transmits it on its medium.
  136.  *
  137.  * On input, each interface unwraps the data received by it, and either
  138.  * places it on the input queue of a internetwork datagram routine
  139.  * and posts the associated software interrupt, or passes the datagram to a raw
  140.  * packet input routine.
  141.  *
  142.  * Routines exist for locating interfaces by their addresses
  143.  * or for locating a interface on a certain network, as well as more general
  144.  * routing and gateway routines maintaining information used to locate
  145.  * interfaces.  These routines live in the files if.c and route.c
  146.  */
  147. #ifndef _TIME_ /*  XXX fast fix for SNMP, going away soon */
  148. #include <sys/time.h>
  149. #endif
  150.  
  151. /*
  152.  * Structure defining a queue for a network interface.
  153.  *
  154.  * (Would like to call this struct ``if'', but C isn't PL/1.)
  155.  */
  156.  
  157. struct    ifqueue {
  158.   struct    mbuf *ifq_head;
  159.   struct    mbuf *ifq_tail;
  160.   int    ifq_len;
  161.   int    ifq_maxlen;
  162.   int    ifq_drops;
  163. };            
  164.  
  165. struct ifnet {
  166.     char    *if_name;        /* name, e.g. ``en'' or ``lo'' */
  167.     short    if_unit;        /* sub-unit for lower level driver */
  168.     short    if_mtu;            /* maximum transmission unit */
  169.     short    if_flags;        /* up/down, broadcast, etc. */
  170.     short    if_timer;        /* time 'til if_watchdog called */
  171.     int    if_metric;        /* routing metric (external only) */
  172.     struct    ifaddr *if_addrlist;    /* linked list of addresses per if */
  173.     struct  ifqueue if_snd;        /* output queue */
  174. /* procedure handles */
  175.     int    (*if_init)();        /* init routine */
  176.     int    (*if_output)(struct ifnet *,    /* output routine (enqueue) */ 
  177.                  struct mbuf *, 
  178.                  struct sockaddr *, struct rtentry *);
  179.     int    (*if_start)();        /* initiate output routine */
  180.     int    (*if_done)();        /* output complete routine */
  181.     int    (*if_ioctl)(struct ifnet *, int, caddr_t); /* ioctl routine */
  182.     int    (*if_reset)();        /* bus reset routine */
  183.     int    (*if_watchdog)();    /* timer routine */
  184. /* generic interface statistics */
  185.     int    if_ipackets;        /* packets received on interface */
  186.     int    if_ierrors;        /* input errors on interface */
  187.     int    if_opackets;        /* packets sent on interface */
  188.     int    if_oerrors;        /* output errors on interface */
  189.     int    if_collisions;        /* collisions on csma interfaces */
  190. /* end statistics */
  191.     struct    ifnet *if_next;
  192.     u_char    if_type;        /* ethernet, tokenring, etc */
  193.     u_char    if_addrlen;        /* media address length */
  194.     u_char    if_hdrlen;        /* media header length */
  195.     u_char    if_index;        /* numeric abbreviation for this if  */
  196. /* more statistics here to avoid recompiling netstat */
  197.     struct    timeval if_lastchange;    /* last updated */
  198.     int    if_ibytes;        /* total number of octets received */
  199.     int    if_obytes;        /* total number of octets sent */
  200.     int    if_imcasts;        /* packets received via multicast */
  201.     int    if_omcasts;        /* packets sent via multicast */
  202.     int    if_iqdrops;        /* dropped on input, this interface */
  203.     int    if_noproto;        /* destined for unsupported protocol */
  204.     int    if_baudrate;        /* linespeed */
  205.         int    if_pcount;        /* number of promiscuous listeners */
  206. };
  207.  
  208. #define    IFF_UP        0x1        /* interface is up */
  209. #define    IFF_BROADCAST    0x2        /* broadcast address valid */
  210. #define    IFF_DEBUG    0x4        /* turn on debugging */
  211. #define    IFF_LOOPBACK    0x8        /* is a loopback net */
  212. #define    IFF_POINTOPOINT    0x10        /* interface is point-to-point link */
  213. #define    IFF_NOTRAILERS    0x20        /* avoid use of trailers */
  214. #define    IFF_RUNNING    0x40        /* resources allocated */
  215. #define    IFF_NOARP    0x80        /* no address resolution protocol */
  216. /* next two not supported now, but reserved: */
  217. #define    IFF_PROMISC    0x100        /* receive all packets */
  218. #define    IFF_ALLMULTI    0x200        /* receive all multicast packets */
  219. #define    IFF_OACTIVE    0x400        /* transmission in progress */
  220. #define    IFF_SIMPLEX    0x800        /* can't hear own transmissions */
  221.  
  222. /* flags set internally only: */
  223. #define    IFF_CANTCHANGE \
  224.     (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|IFF_SIMPLEX)
  225.  
  226. /*
  227.  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
  228.  * input routines have queues of messages stored on ifqueue structures
  229.  * (defined above).  Entries are added to and deleted from these structures
  230.  * by these macros, which should be called with ipl raised to splimp().
  231.  */
  232. #define    IF_QFULL(ifq)        ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
  233. #define    IF_DROP(ifq)        ((ifq)->ifq_drops++)
  234. #define    IF_ENQUEUE(ifq, m) { \
  235.     (m)->m_nextpkt = 0; \
  236.     if ((ifq)->ifq_tail == 0) \
  237.         (ifq)->ifq_head = m; \
  238.     else \
  239.         (ifq)->ifq_tail->m_nextpkt = m; \
  240.     (ifq)->ifq_tail = m; \
  241.     (ifq)->ifq_len++; \
  242. }
  243. #define    IF_PREPEND(ifq, m) { \
  244.     (m)->m_nextpkt = (ifq)->ifq_head; \
  245.     if ((ifq)->ifq_tail == 0) \
  246.         (ifq)->ifq_tail = (m); \
  247.     (ifq)->ifq_head = (m); \
  248.     (ifq)->ifq_len++; \
  249. }
  250. #define    IF_DEQUEUE(ifq, m) { \
  251.     (m) = (ifq)->ifq_head; \
  252.     if (m) { \
  253.         if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
  254.             (ifq)->ifq_tail = 0; \
  255.         (m)->m_nextpkt = 0; \
  256.         (ifq)->ifq_len--; \
  257.     } \
  258. }
  259.  
  260. #define    IFQ_MAXLEN    50
  261. #define    IFNET_SLOWHZ    1        /* granularity is 1 second */
  262.  
  263. /*
  264.  * The ifaddr structure contains information about one address
  265.  * of an interface.  They are maintained by the different address families,
  266.  * are allocated and attached when an address is set, and are linked
  267.  * together so all addresses for an interface can be located.
  268.  */
  269. struct ifaddr {
  270.     struct    sockaddr *ifa_addr;    /* address of interface */
  271.     struct    sockaddr *ifa_dstaddr;    /* other end of p-to-p link */
  272. #define    ifa_broadaddr    ifa_dstaddr    /* broadcast address interface */
  273.     struct    sockaddr *ifa_netmask;    /* used to determine subnet */
  274.     struct    ifnet *ifa_ifp;        /* back-pointer to interface */
  275.     struct    ifaddr *ifa_next;    /* next address for interface */
  276.     void    (*ifa_rtrequest)(int,     /* check or clean routes (+ or -)'d */
  277.                  struct rtentry *, struct sockaddr *);
  278.     struct     rtentry *ifa_rt;    /* ??? for ROUTETOIF */
  279.     u_short    ifa_flags;        /* mostly rt_flags for cloning */
  280.     u_short    ifa_llinfolen;        /* extra to malloc for link info */
  281. };
  282. #define IFA_ROUTE    RTF_UP        /* route installed */
  283. /*
  284.  * Interface request structure used for socket
  285.  * ioctl's.  All interface ioctl's must have parameter
  286.  * definitions which begin with ifr_name.  The
  287.  * remainder may be interface specific.
  288.  */
  289. struct    ifreq {
  290. #define    IFNAMSIZ    64
  291.     char    ifr_name[IFNAMSIZ];        /* if name, e.g. "en0" */
  292.     union {
  293.         struct    sockaddr ifru_addr;
  294.         struct    sockaddr ifru_dstaddr;
  295.         struct    sockaddr ifru_broadaddr;
  296.         short    ifru_flags;
  297.         int    ifru_metric;
  298.         caddr_t    ifru_data;
  299.     } ifr_ifru;
  300. #define    ifr_addr    ifr_ifru.ifru_addr    /* address */
  301. #define    ifr_dstaddr    ifr_ifru.ifru_dstaddr    /* other end of p-to-p link */
  302. #define    ifr_broadaddr    ifr_ifru.ifru_broadaddr    /* broadcast address */
  303. #define    ifr_flags    ifr_ifru.ifru_flags    /* flags */
  304. #define    ifr_metric    ifr_ifru.ifru_metric    /* metric */
  305. #define    ifr_data    ifr_ifru.ifru_data    /* for use by interface */
  306. };
  307.  
  308. struct ifaliasreq {
  309.     char    ifra_name[IFNAMSIZ];        /* if name, e.g. "en0" */
  310.     struct    sockaddr ifra_addr;
  311.     struct    sockaddr ifra_broadaddr;
  312.     struct    sockaddr ifra_mask;
  313. };
  314.  
  315. /*
  316.  * Structure used in SIOCGIFCONF request.
  317.  * Used to retrieve interface configuration
  318.  * for machine (useful for programs which
  319.  * must know all networks accessible).
  320.  */
  321. struct    ifconf {
  322.     int    ifc_len;        /* size of associated buffer */
  323.     union {
  324.         caddr_t    ifcu_buf;
  325.         struct    ifreq *ifcu_req;
  326.     } ifc_ifcu;
  327. #define    ifc_buf    ifc_ifcu.ifcu_buf    /* buffer address */
  328. #define    ifc_req    ifc_ifcu.ifcu_req    /* array of structures returned */
  329. };
  330.  
  331. #ifndef IF_ARP_H
  332. #include <net/if_arp.h>
  333. #endif
  334.  
  335. #ifdef KERNEL
  336. extern struct    ifnet *ifnet;
  337. extern struct    ifqueue rawintrq;        /* raw packet input queue */
  338. #include <net/if_protos.h>
  339. #include <net/if_loop_protos.h>
  340. #endif /* KERNEL */
  341.  
  342. #endif /* IF_H */
  343.